import java.util.Stack;
import java.util.TreeMap;

/**
 * Created by zhourh on 2018/9/11.
 */
public class MinStack {

    /** initialize your data structure here. */

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.getMin());
    }

    Stack<Integer> stack;
    Stack<Integer> minStack;

    int min = Integer.MAX_VALUE;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int x) {
        min = Math.min(x, min);
        stack.push(x);
        minStack.push(min);
    }

    public void pop() {
        stack.pop();
        minStack.pop();
        if (!minStack.isEmpty()) {
            min = minStack.peek();
        } else {
            min = Integer.MAX_VALUE;
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min;
    }
}
